<template>
	<view class="content" style="background-color: #f5f5f5;">
		<u-navbar scrollable=false titleStyle="font-size:40rpx;color:#333" :placeholder='true'
			:title="title" :autoBack="true">
		</u-navbar>
		<view class="input">
			<view class="title co3 fontS32">请再次输入{{type==5?'账户':"支付"}}密码</view>

			<view class="code">
				<u-code-input @finish="finish()" v-model="value" :maxlength="6" dot></u-code-input>
			</view>
			<!-- <u-keyboard :closeOnClickOverlay="false"  :dotDisabled="true" :tooltip="false" :showTips="false" :showCancel="false" :showConfirm="false" ref="uKeyboard" mode="number" :show="show"></u-keyboard> -->

		</view>
	</view>

</template>



<script>
	export default {
		data() {
			return {
				title:'',
				type: 2, // 2为设置密码和修改密码 3为修改密码的（忘记密码） 5设置账户密码
				value: '',
				show: false,
				data: {}, //上一个页面传过来的参数
			}
		},
		onLoad(op) {
			this.data = JSON.parse(op.data)
			this.type = this.data.type
			console.log(this.data)
			if(this.type==2 && this.data.old_pay_pwd){
				this.title='修改密码'
			}else if(this.type==3){
				this.title='修改密码'
			} else if(this.type==2 && uni.getStorageSync('userInfo').is_pay_pwd){
				this.title='忘记密码'
			}else if(this.type==2 ){
			    this.title='设置密码'
			}
		},
		methods: {
			go() {
				console.log(12313);
			},
			finish() {
				if (this.type == 2) {
					if (!(this.data.pay_pwd == this.value)) {
						this.$my.toast('两次密码不一致')
						return
					}
				} else if (this.type == 3) {
					if (!(this.data.now_pay_pwd == this.value)) {
						this.$my.toast('两次密码不一致') 
						return
					}
				}
				this.$my.post('/index/user/update_user_auth', this.data).then(res => {
					this.$my.toast(res.message)
					if (res.code == 200) {
						if (this.type == 2) {
							let userInfo = uni.getStorageSync('userInfo')
							userInfo.is_pay_pwd = true
							uni.setStorageSync("userInfo", userInfo)
						}
						this.$my.go('/pages/my/set/success', 500)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.input {
			height: 100rpx;
			// background-color: tomato;
			margin-top: 200rpx;

			.title {
				// background-color: red;
				text-align: center;
			}

			.code {
				margin-top: 54rpx;
				display: flex;
				justify-content: center;
			}

		}
	}
</style>
